package com.example.asus.homework11.model;

import android.provider.SyncStateContract;

import com.example.asus.homework11.bean.RegisterBean;
import com.example.asus.homework11.listener.RetrofitListener;
import com.example.asus.homework11.retrofitservice.RegisterService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import android.provider.SyncStateContract.Constants;

import static com.example.asus.homework11.model.Contants.BASE_URL;

/**
 * Created by 彭立翔 on 2018/10/15.
 * Coder Level:MAX.
 */

public class RetrofitBaseModel {

    protected Retrofit retrofit;
    public RetrofitBaseModel(){
        retrofit = new Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).build();


    }
    public <T> void bindCallback(Call<T>call,final RetrofitListener<T> listener,final int flag){
        Callback<T> callback = new Callback<T>() {
            @Override
            public void onResponse(Call<T> call, Response<T> response) {
                listener.onSuccess(response.body(),flag);
            }

            @Override
            public void onFailure(Call<T> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
}
